//
//  MainTabBarController.swift
//  maopu
//
//  Created by 黄海波 on 2017/4/1.
//  Copyright © 2017年 maopu. All rights reserved.
//

import UIKit

class MainTabBarController: UITabBarController {
    
    var selected_Index:Int = 0{
        didSet{
            self.selectedIndex = selected_Index
        }
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.initializeAllChildViewController()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        
    }
    
    fileprivate func initializeAllChildViewController(){
        tabBaraAddChildViewController(vc: HomePageViewController(), title: "大杂烩", imageName: "home_ico", selectedImageName: "home_ico_hl" , tag:  100)
        tabBaraAddChildViewController(vc: VideoViewController(), title: "猫眼", imageName: "video_ico", selectedImageName: "video_ioc_hl" , tag:  101)
        tabBaraAddChildViewController(vc: MyPageController(), title: "账户", imageName: "my_ico", selectedImageName: "my_ico" , tag:  102)
    }
    
    fileprivate func tabBaraAddChildViewController(vc: UIViewController, title: String, imageName: String, selectedImageName: String , tag:Int){
        let image = UIImage(named: imageName)!.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        let selectImage = UIImage(named: selectedImageName)!.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        vc.tabBarItem = UITabBarItem(title: title, image: image, selectedImage: selectImage)
        vc.tabBarItem.titlePositionAdjustment = UIOffsetMake(0, -2)
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.RGB(r: 136, g: 136, b: 136) ,NSFontAttributeName:UIFont.systemFont(ofSize: 10)] , for: UIControlState())
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.red , NSFontAttributeName:UIFont.systemFont(ofSize: 10)],
                                             for: UIControlState.selected)
        vc.tabBarItem.tag = tag
        addChildViewController(BaseNavigationController(rootViewController: vc))
    }

}
